package org.softmed.rest.editor.tabs;

import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;

import net.miginfocom.swing.MigLayout;

import org.softmed.rest.editor.commons.SwingUtil;
import org.softmed.swing.IconManager;

public class CloseTabHeader extends JPanel implements ActionListener {

	JButton button = new JButton(IconManager.remove);
	JLabel label = new JLabel("");
	JTabbedPane tabPane;

	public CloseTabHeader(String title, JTabbedPane tabPane) {
		this.tabPane = tabPane;
		label.setText(title);
		MigLayout layout = new MigLayout("left,insets 0");
		setLayout(layout);
		SwingUtil.setSize(this, 90, 15);

		SwingUtil.setSize(button, 15, 15);
		SwingUtil.setSize(label, 70, 15);

		add(label);
		add(button);

		button.addActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		int index = tabPane.indexOfTabComponent(this);
		tabPane.remove(index);
	}
}
